package com.aliyunlog.utils;

import com.aliyunlog.model.LogItemResult;

/**
 *
 * @author tanson lam
 * @creation 2017年6月25日
 * 
 */
public class LogItemWarnSender {
	/**
	 * 钉钉每次发送
	 */
	private final static int MAXLINE = 10; 
	

	public static void sendLogItemResult(LogItemResult logItemResult, String dingdingUrl) {
		int line = 0;
		int messageCount = logItemResult.getMessageCount();
		StringBuffer sendContent = new StringBuffer();
		for (int i = 0; i < messageCount; i++) {  
			sendContent.append(logItemResult.getMessageList().get(i));
			if (line == MAXLINE || i == messageCount - 1) {
				try {
					String result = DingDingWarnUtil.sendDingtalk(dingdingUrl,
							logItemResult.getTitle()+sendContent.toString());
					LogManager.log("send to dingdingtalk result:" + result);
				} catch (Exception e) {
					e.printStackTrace();
				}
				sendContent.delete(0, sendContent.length() - 1);
				line = 0;

			}
			line++;
		}
	}

}
